package com.ericzong.renamer.converter.string;

import org.apache.commons.lang3.StringUtils;

import com.ericzong.renamer.model.Record;

public class ReplaceStringConverter extends AbstractStringConverter
{
	private boolean regex;
	private String oldString;
	private String newString;
	
	public ReplaceStringConverter()
	{
		regex = false;
		oldString = StringUtils.EMPTY;
		newString = StringUtils.EMPTY;
	}

	@Override
	public void convert(Record record)
	{
		String target = record.getSource();
		
		if(StringUtils.isNoneEmpty(oldString))
		{
			if(regex)
			{
				target = target.replaceAll(oldString, newString);
			}
			else
			{
				target = target.replace(oldString, newString);
			}
		}
		
		record.setTarget(target.toString());
	}

	public boolean isRegex()
	{
		return regex;
	}

	public void setRegex(boolean regex)
	{
		this.regex = regex;
	}

	public String getOldString()
	{
		return oldString;
	}

	public void setOldString(String oldString)
	{
		this.oldString = oldString;
	}

	public String getNewString()
	{
		return newString;
	}

	public void setNewString(String newString)
	{
		this.newString = newString;
	}

}
